package com.authine.cloudpivot.app.openapi.config;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.gateway.config.LoadBalancerProperties;
import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.DispatcherHandler;

/**
 * AutoConfiguration
 *
 * @author Spencer Gibb
 * @author Olga Maciaszek-Sharma
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({LoadBalancerClient.class, RibbonAutoConfiguration.class,
        DispatcherHandler.class})
@AutoConfigureAfter(RibbonAutoConfiguration.class)
@EnableConfigurationProperties(LoadBalancerProperties.class)
public class LocalDebugGatewayLoadBalancerClientAutoConfiguration {


    @Bean("properties")
    public LoadBalancerProperties loadBalancerProperties() {
        LoadBalancerProperties loadBalancerProperties = new LoadBalancerProperties();
        loadBalancerProperties.setUse404(true);
        return loadBalancerProperties;
    }

    @Bean
    public LocalDebugLoadBalancerClientFilter loadBalancerClientFilter(LocalDebugLoadBalancerClient client,
                                                                       LoadBalancerProperties properties) {
        return new LocalDebugLoadBalancerClientFilter(client, properties);
    }

}